<?php

require_once PATH_LIB.'database.php';

class base extends stdClass{
  /**
   *
   * @param array $array
   * @return base 
   */
  function __construct($array) {
    $this->array2Prop($array);
    return $this;
  }
  
  protected function array2Prop($array){
    
    if(is_array($array)){
      foreach($array as $key=>$value){
        $this->{$key} = is_array($value) ? array2Obj($value) : $value;
      }
    }

    return($this);
  }
  
  /**
   * 
   * @param type $nomDb
   * @param string $nomUser
   * @param type $pwdDb
   * @param string $serverName
   * @return DataBase $db
   */
  public static function getDb($nomDb=null,$nomUser=null,$pwdDb=null,$serverName=null){
    
    if(!isset($nomDb))        $nomDb      = NOM_DB;
    if(!isset($nomUser))      $nomUser    = NOM_USER;
    if(!isset($pwdDb))        $pwdDb      = PWD_DB;
    if(!isset($serverName))   $serverName = SERVER_NAME;
    
    $db = new DataBase($nomDb,$nomUser,$pwdDb,$serverName);
    return $db;
  
    
  }
}

